//@author A0083782W

//ActionList class
//Singleton protocal is followed
//This is the class which stores all the pass actions
//It is used to perform an undo action.
//Actions consist of add/delete/modify only
//In order to perform undo, events need to be pushed into the list
//For add and delete, simply push the operation type and event into the actionlist
//For modify and mark, you need to push the event before modification and after modification
//into the list
//For undo, just use pop. And execute the command from the pop.
//Howeve, before this you need to check if the command type is modify.
//If it is, you will need to pop twice.

#pragma once

#include "SingleAction.h"

class UserCommand;
class PassedAction: public SingleAction {
public:
	//reverse will reverse the command, from add to delete,
	//from modify to delete
	UserCommand reverse();

	void setActionTime (const Time& newTime);
	
	using SingleAction::setActionTime;
};

class ActionList {
private:
	vector<PassedAction> _actionStack;
	ActionList& operator = (const ActionList&);
	void reset ();
	ActionList ();
	bool midOfModify;
	ActionList (const ActionList& newAction);
	
public:
	//get the only instance
	static ActionList& get();
	
	//to access a certain memeber of the list
	//two modify actions are deem as one
	const PassedAction& operator[] (pos_int rightOperand) const;
	
	//peek to see if the current action is modify
	bool peek_isModify() const;

	//get the size of the vector
	pos_int size() const;

	//get the number of the action
	pos_int sizeOfActions() const;

	//push an action into the list
	void push (const UserCommand& currentCommand);
	void push (const Event& currentEvent, OperationType currentOperation);
	
	//pop an action that can be executed by Operation
	UserCommand pop();
};

#include "UserCommand.h"
typedef ActionList * const ActionListPtr;